﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

#if USE_OPENJTALK
namespace NicoView.Model.Platform.Speech.OpenJTalk
{
    public sealed class OpenJTalkSpeacher : SpeacherBase<GeneralLearnModel>
    {
        public OpenJTalkSpeacher(string name, string voiceDictoionaryDir, string synthesizerDictionary, RegexLearnDictionary regexDictionary, LearnDictionary dictionary)
            : base(regexDictionary,dictionary) 
        {

            _synthesizer = new OpenJTalkSynthesizer();

            _synthesizer.Load(voiceDictoionaryDir, new string[] { synthesizerDictionary }, 1, new double[] { 48000, 12000, 240, 0.9, 0.5, 0.55, 0.7 }, 1);
            _name = name;


        }


        private OpenJTalkSynthesizer _synthesizer;



        private string _name;


        protected override void Synthesize(SynthesizeArgs args)
        {

            lock (_synthesizer)
            {

                _synthesizer.Prepare(args.Body + " " + args.Name);
                _synthesizer.Synthesize();

                
            }

        }

        public override void SpeechCancel()
        {

            _synthesizer.Stop();
        }

        public override void Dispose()
        {

            SpeechCancel();
            lock (_synthesizer)
            {
                
                _synthesizer.Dispose();
            }
        }

        public override string Name
        {
            get { return _name; }

        }
    }
}
#endif
